package com.study.leetcode;

import java.util.ArrayList;
import java.util.List;
//https://leetcode.cn/problems/binary-tree-paths/
public class Solution_257 {
    List<String> paths = new ArrayList<>();

    public List<String> binaryTreePaths(TreeNode root) {
        dfs(root, "");
        return paths;
    }

    private void dfs(TreeNode root, String s) {
        if (root == null) {
            return;
        }
        if (root.left == null && root.right == null) {
            paths.add(s + root.val);
            return;
        }
        if (root.left != null) {
            dfs(root.left, s + root.val + "->");
        }
        if (root.right != null) {
            dfs(root.right, s + root.val + "->");
        }

    }

    public static void main(String[] args) {

    }
}
